package com.hbnu.system.controller;


import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.entity.Achievement;
import com.hbnu.system.model.entity.AchievementFile;
import com.hbnu.system.model.query.AchievementPageQuery;
import com.hbnu.system.model.vo.AchievementVO;
import com.hbnu.system.service.AchievementFileService;
import com.hbnu.system.service.AchievementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 科研成果表(Achievement)表控制层
 *
 * @author makejava
 * @since 2025-07-21 15:59:40
 */
@RestController
@RequestMapping("/achievement")
@Api(tags = "科研成果模块(咨询报告、社情民意)")
public class AchievementController {


    @Autowired
    private AchievementService achievementService;
    @Autowired
    private AchievementFileService achievementfileService;

    @ApiOperation("科研成果-正式录入")
    @PostMapping("/addAchievement")
    public Rest<Boolean> AddAchievement(@RequestBody Achievement achievement){
        boolean add = achievementService.addAchievement(achievement);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研成果-删除")
    @GetMapping("/deleteAchievement")
    public Rest<Boolean> deleteAchievement(String achievementID) throws IOException {
        boolean delete = achievementService.deleteAchievement(achievementID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研成果-名称查重")
    @GetMapping("/CheckAchievementName")
    public Rest<Boolean> CheckAchievementName(String achievement_name){
        boolean check = achievementService.checkAchievementName(achievement_name);
        return check ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研成果-修改")
    @PostMapping("/UpdateAchievement")
    public Rest<Boolean> UpdateAchievement(@RequestBody Achievement achievement){
        boolean update = achievementService.updateAchievement(achievement);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键科研成果查询")
    @GetMapping("/GetAchievementById")
    public Rest<Achievement> GetAchievementDTOById(String achievementID){
        Achievement achievementdto = achievementService.getAchievementById(achievementID);
        return Rest.success(achievementdto);
    }

//    @ApiOperation("根据主键科研成果DTO查询")
//    @GetMapping("/GetAchievementDTOById")
//    public Rest<AchievementDTO> GetAchievementDTOById(String achievementID){
//        AchievementDTO achievementdto = achievementService.getAchievementDTOById(achievementID);
//        return Rest.success(achievementdto);
//    }

    @ApiOperation("科研成果-院级通过")
    @GetMapping("/CollegeCheckPass")
    public Rest<String> CollegePassPaper(@RequestHeader("X-Token") String token,String PaID){
        Boolean b = achievementService.collegeCheckPass(token ,PaID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研成果-院级打回")
    @PostMapping("/CollegeCheckBack")
    public Rest<String> CollegeBackPaper(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = achievementService.collegeCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研成果-校级通过")
    @GetMapping("/SchoolCheckPass")
    public Rest<String> SchoolPassPaper(@RequestHeader("X-Token") String token,String PaID){
        Boolean b = achievementService.schoolCheckPass(token,PaID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研成果-校级打回")
    @PostMapping("/SchoolCheckBack")
    public Rest<String> SchoolBackPaper(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = achievementService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("科研成果-提交")
    @PostMapping("/ReCommitAchievement")
    public Rest<Boolean> ReCommitAchievement(String achievementID){
        boolean add = achievementService.ReCommitAchievement(achievementID);
        return add ? Rest.success() : Rest.failed();
    }
    
    @ApiOperation("科研成果-撤回")
    @PostMapping("/WithdrawAchievement")
    public Rest<String> WithdrawAchievement(@RequestHeader("X-Token") String token, String achievementID){
        Boolean b = achievementService.withdrawAchievement(token, achievementID);
        return b ? Rest.success() : Rest.failed();
    }

    @ApiOperation("用户获取与自己相关的科研成果-分页")
    @PostMapping("/UserGetRelateAchievement")
    public Rest<CommonPage<AchievementVO>> UserGetRelateAchievement(@RequestBody AchievementPageQuery achievementPageQuery){
        CommonPage<AchievementVO> achievementVOCommonPage = achievementService.userGetRelateAchievement(achievementPageQuery);
        return Rest.success(achievementVOCommonPage);
    }

    @ApiOperation("科研成果-文件信息上传")
    @PostMapping("/addachievementfile")
    public Rest<Boolean> addachievementfile(@RequestBody AchievementFile achievementfile){
        boolean add = achievementfileService.addAchievementFile(achievementfile);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("科研成果-文件信息删除")
    @GetMapping("/Deleteachievementfile")
    public Rest<Boolean> Deleteachievementfile(String id)throws IOException {
        boolean delete = achievementfileService.deletAchievementFile(id);
        return delete ? Rest.success() : Rest.failed();
    }
    @ApiOperation("科研成果-文件信息分页查询")
    @GetMapping ("/pageachievementfileCondition")
    public Rest<List<AchievementFile>> pageachievementfileConditionfile(String id){
        List<AchievementFile> page = achievementfileService.pageAchievementFile(id);
        return Rest.success(page);
    }

    @ApiOperation("科研成果导出")
    @PostMapping("export")
    public Rest<CommonPage<Achievement>> export(@RequestBody AchievementPageQuery achievementPageQuery) {
        CommonPage<Achievement> achievementCommonPage = achievementService.export(achievementPageQuery);
        return Rest.success(achievementCommonPage);
    }

}

